FROM 172.25.4.11/public/openjdk:8-alpine-font-0328

# Define all environment variable here
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV TZ='Asia/Shanghai'
ENV APP_HOME /usr/app
ENV UID=166
ENV GID=166
ENV USER_NAME=eguser
ENV GROUP_NAME=eggroup
ENV ENV="/etc/profile"

# # CREATE APP USER ##
# Set umask
RUN sed -i "s|umask 022|umask 027|g" /etc/profile

# Create the home directory for the new app user.
RUN mkdir -p /usr/app
RUN mkdir -p /usr/app/bin
RUN mkdir -p /tmp/upload
RUN mkdir -p /var/cnp/image_file
RUN mkdir -p /var/cnp/image_icon

RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.9/main" > /etc/apk/repositories \
&& echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.9/community" >> /etc/apk/repositories \
&& echo "https://mirror.tuna.tsinghua.edu.cn/alpine/edge/testing" >> /etc/apk/repositories

# Create an app user so our program doesn't run as root.
RUN apk update --allow-untrusted &&\
    apk add shadow --allow-untrusted &&\
    groupadd -r -g $GID $GROUP_NAME &&\
    useradd -r -u $UID -g $GID -d $APP_HOME -s /sbin/nologin -c "Docker image user" $USER_NAME

WORKDIR $APP_HOME

COPY target/*.jar $APP_HOME/bin

RUN chmod 750 $APP_HOME &&\
    chmod 777 /tmp/upload &&\
    chmod -R 550 $APP_HOME/bin &&\
    mkdir -p -m 750 $APP_HOME/log &&\
    chown -R $USER_NAME:$GROUP_NAME $APP_HOME &&\
    chown -R $USER_NAME:$GROUP_NAME $APP_HOME/log

EXPOSE 8067
# Change to the app user.
USER $USER_NAME
# Execute script & application
ENTRYPOINT ["java", "-jar", "./bin/multiclouldmgmt-0.0.1-SNAPSHOT.jar"]
